var dateUtil = {
		
		
		
	
    /**
     * 日期转换
     * yyyy splitStr mm splitStr dd
     * @param {} date  splitStr 分隔字符
     * @return {}
     */
    dateFormat : function(date,splitStr){
        if (date) {
            if(!splitStr){
                splitStr = "/";
            }
            var month = date.month + 1;
            var day = date.date;
            var year = 1900 + date.year;
            if (month < 10)
                month = "0" + month;
            if (day < 10)
                day = "0" + day;
            return year + splitStr + month + splitStr + day;
        } else {
            return "未知";
        }
    },
    
    /**
     * 日期转换
     * yyyy splitStr mm splitStr dd
     * @param {} date  splitStr 分隔字符
     * @return {}
     */
    timeFormat : function(date,splitStr){
        if (date) {
            if(!splitStr){
                splitStr = "/";
            }
            var month = date.getMonth() + 1;
            var day = date.getDate();
            var year = date.getFullYear();
            if (month < 10)
                month = "0" + month;
            if (day < 10)
                day = "0" + day;
            return year + splitStr + month + splitStr + day;
        } else {
            return "未知";
        }
    },
    
    /**
     * 日期转换
     * yyyy splitStr mm splitStr dd hh:mm:ss
     * @param {} date  splitStr 分隔字符
     * @return {}
     */
    dateFormatSec : function(date,splitStr){
        if (date) {
            if(!splitStr){
                splitStr = "/";
            }
            var month = parseInt(date.month)<9?"0"+(date.month+1):date.month+1;
            var day = parseInt(date.date)<10?"0"+date.date:date.date;
            var year = 1900 + date.year;
            var hours = parseInt(date.hours)<10?"0"+date.hours:date.hours;
            var minutes = parseInt(date.minutes)<10?"0"+date.minutes:date.minutes;
            var seconds = parseInt(date.seconds)<10?"0"+date.seconds:date.seconds;
            return year + splitStr + month + splitStr + day + ' ' + hours + ':' + minutes + ':' + seconds;
        } else {
            return "未知";
        }
    },
    /**
     * 格式化日期
     * 今天 19：09/ 昨天 19:12 / 5月4日 19:09 
     */
    dateFormat_style : function(date) {
        var dateStr = (date.year + 1900) + '/' + (date.month + 1) + '/'
                + date.date;
        var timeStr = date.hours + ':'
                + (date.minutes < 10 ? '0' + date.minutes : date.minutes);
        var today = new Date();
        var todayStr = today.getFullYear() + '/' + (today.getMonth() + 1) + '/'
                + today.getDate();
        var d = new Date(dateStr);
        var todayDate = new Date(todayStr);
        var newdate;
        if (todayDate - d == 0) {
            newdate = '今天   ' + timeStr;
        } else if (todayDate - d == 86400000) {
            newdate = '昨天   ' + timeStr;
        } else {
            newdate = (date.month + 1) + '月' + date.date + '日' + '    '
                    + timeStr;
        }
        return newdate;
    },
    /**
     * 计算时间差
     * */
    comparteDateMin:function(start,end,type){
    	var date1=new Date(Date.parse(start.replace(/-/g,   "/")));  //开始时间
    	var date2=new Date(Date.parse(end.replace(/-/g,   "/")));    //结束时间
    	var date3=date2.getTime()-date1.getTime();  //时间差的毫秒数
    	 
    	//计算出相差天数
    	var days=Math.floor(date3/(24*3600*1000));
    	 

    	//计算出小时数
    	var leave1=date3%(24*3600*1000) ;   //计算天数后剩余的毫秒数
    	var hours=Math.floor(leave1/(3600*1000));
    	//计算相差分钟数
    	var leave2=leave1%(3600*1000);        //计算小时数后剩余的毫秒数
    	var minutes=Math.floor(leave2/(60*1000));

    	 
    	//计算相差秒数
    	var leave3=leave2%(60*1000);      //计算分钟数后剩余的毫秒数
    	var seconds=Math.round(leave3/1000);
    	if(type=="d"){
    		return days;
    	}else if(type=="h"){
    		return hours;
    	}else if(type="m"){
    		return minutes;
    	}else{
    		return seconds;
    	}
    },
    AddDays : function(dt, days){
        var hsm = dt.split(' ')[1];//时分秒
        dt = dt.replace(/-/g,'/');//js不认2000-1-31,只认2000/1/31
        var t1 = new Date(new Date(dt).valueOf() + days*24*60*60*1000);// 日期加上指定的天数
        var mon = ((t1.getMonth() + 1)>9?(t1.getMonth() + 1):'0'+(t1.getMonth() + 1));
        var day = (t1.getDate()>9?t1.getDate():'0'+t1.getDate());
        return t1.getFullYear() + "-" + mon + "-" + day+' '+hsm;
    },
    /**
     * 计算天数
     * 格式:2010-06-20 12:12
     * @param {} date1
     * @param {} date2
     * @return {}
     */
    compareDate : function(date1, date2) {
        if(date1 && date2){
            date1 = dateUtil.dateFormat(date1);
            date2 = dateUtil.dateFormat(date2);
            var time = new Date(date2.replace(/-/g, "\-")).getTime()
                    - new Date(date1.replace(/-/g, "\-")).getTime();
            // 开始时间晚于结束时间
            if (time < 0)
                return time;
            // 计算天数
            return time / (86400 * 1000) + 1;
        }else{
            return "未知";
        }
    },
    
     /**
     * 计算天数
     * @param {} str
     * @param {} str
     * @return {}
     */
    compareTimeStr : function(date1, date2) {
        if(date1 && date2){
            date1 = dateUtil.str2Date(date1);
            date2 = dateUtil.str2Date(date2);
            var time = date2-date1;
            // 开始时间晚于结束时间
            if (time < 0)
                return time;
            // 计算天数
            return time / (86400 * 1000) + 1;
        }else{
            return "未知";
        }
    },
   
   /**
     * 字符串转日期
     * @param {} str
     * @param {} str
     * @return {}
     */
    str2Date:function(dateStr,splitStr){
         splitStr = splitStr || '-';
         var arr = dateStr.split(splitStr);
         //alert(dateStr.split(splitStr)[0]+"..."+dateStr.split(splitStr)[1]+".."+dateStr.split(splitStr)[2]);
         return new Date(arr[0],parseInt(arr[1])-1,arr[2]);
    },
    
    /**
     * 日期转字符串
     * @param {} date
     * @param {} str
     * @return {}
     */
    date2Str:function(date,splitStr){
         if(!splitStr)
         {
            splitStr="-";
         }
         var year = date.getFullYear();
         var month = date.getMonth()+1;
         var day = date.getDate();
         if (month < 10)
				month = "0" + month;
	     if (day < 10)
				day = "0" + day;
		return year + splitStr + month + splitStr + day;
    },
    
    
    
    /**
     * 时间转换成String
     */
    getDate : function(curDate) {
		if (curDate) {
			var month = curDate.month + 1;
			var day = curDate.date;
			var year = 1900 + curDate.year;
			if (month < 10)
				month = "0" + month;
			if (day < 10)
				day = "0" + day;
			return year + "-" + month + "-" + day;
		} else {
			return "";
		}
	},
	
	/**
	 * 计算date与当前时间差(客户端时间)
	 * @param {} date
	 * @return {String}
	 */
	checkTimeStep : function(date){
		if(date){
			if(date == 1){
			     return "刚刚";
			}
            date1 = dateUtil.dateFormatSec(date);
            var time = new Date().getTime() - new Date(date1.replace(/-/g, "\-")).getTime();
            // 开始时间晚于结束时间
            if(time < 0){
                return "刚刚";
            }else if(time <= 60000){
                return "约"+Math.ceil(time/1000)+"秒前";
            }else if(time <= 3600000){
                return "约"+Math.ceil(time/60000)+"分钟前";
            }else if(time <= 86400000){
                return "约"+Math.ceil(time/3600000)+"小时前";
            }else{
                return dateUtil.dateFormat_style(date);
            }
		}else{
			return "";
		}
	},
	/**
	 *yyyymmddHHmmss转换为yyyy-mm-dd HH:mm:ss
	 * 
	 * */
	transdate:function(endTime){
		if(endTime.indexOf("-")>0){
			return endTime;
		}
//		var date=new Date();
//		date.setFullYear(endTime.substring(0,4));
//		date.setMonth(endTime.substring(4,6));
//		date.setDate(endTime.substring(6,8));
//		date.setHours(endTime.substring(8,10));
//		date.setMinutes(endTime.substring(10,12));
//		date.setSeconds(endTime.substring(12,15));
		
		return endTime.substring(0,4)+"-"+endTime.substring(4,6)+"-"+endTime.substring(6,8)+" "+endTime.substring(8,10)+":"+endTime.substring(10,12)+":"+endTime.substring(12,15);
//		return date;
	},
	/**
     * 计算date与当前系统时间差
     * @param {} date
     * @return {String}
     */
    checkTwoTimeStep : function(date, sysDate){
        if(date){
            if(date == 1){
                 return "刚刚";
            }
            var date1 = dateUtil.dateFormatSec(date);
            var date2 = dateUtil.dateFormatSec(sysDate);
            var time = new Date(date2.replace(/-/g, "\-")).getTime() - new Date(date1.replace(/-/g, "\-")).getTime();
            // 开始时间晚于结束时间
            if(time < 0){
                return "刚刚";
            }else if(time <= 60000){
                return "约"+Math.ceil(time/1000)+"秒前";
            }else if(time <= 3600000){
                return "约"+Math.ceil(time/60000)+"分钟前";
            }else if(time <= 86400000){
                return "约"+Math.ceil(time/3600000)+"小时前";
            }else{
                return dateUtil.dateFormat_style(date);
            }
        }else{
            return "";
        }
    },
    
    transformMin : function(minute){
    	var str = "";
    	var tempMin = "";
    	if(minute && minute > 0){
    		var m = parseInt(minute);
    		if(minute > 1440){
    			str += Math.floor(minute/1440)+'天';
    			tempMin = minute%1440;
    		}else{
    			tempMin = minute;
    		}
    		if(tempMin > 60){
    			str += Math.floor(tempMin/60)+'小时';
    			tempMin = tempMin%60;
    		}else{
    			tempMin = minute;
    		}
    		str += tempMin+'分';
    	}else{
    		Str = 0;
    	}
    	return str;
    },
    
	dateFormatWeek : function(date) {
		var dateStr = (date.year + 1900) + '-' + (date.month + 1) + '-'
				+ date.date;
		var today = [ "周日", "周一", "周二", "周三", "周四", "周五", "周六" ];
		dateStr = dateStr + '(' + today[date.day] + ')';
		return dateStr;
	},
	
	 //获得上个月在昨天这一天的日期  
  getLastMonthYestdy : function(date){  
     var daysInMonth = new Array([0],[31],[28],[31],[30],[31],[30],[31],[31],[30],[31],[30],[31]);  
     var strYear = date.getFullYear();    
     var strDay = date.getDate();    
     var strMonth = date.getMonth()+1;  
     if((strYear%4 == 0 && strYear%100 != 0)||(strYear%400==0))
     {  
        daysInMonth[2] = 29;  
     }  
     if(strMonth - 1 == 0)  
     {  
        strYear -= 1;  
        strMonth = 12;  
     }  
     else  
     {  
        strMonth -= 1;  
     }  
     strDay = daysInMonth[strMonth] >= strDay ? strDay : daysInMonth[strMonth];  
    if(strMonth<10)    
     {    
        strMonth="0"+strMonth;    
     }  
     if(strDay<10)    
     {    
        strDay="0"+strDay;    
     }  
     datastr = strYear+"-"+strMonth+"-"+strDay; 
     return datastr;  
  },  
	
	dateAdd:function (dateObj, days){
	    var tempDate = dateObj.valueOf();
	    tempDate = tempDate + days * 24 * 60 * 60 * 1000;
	    tempDate = new Date(tempDate);
	    return tempDate;
	},
	addDays : function (datevalues, days,spliter){
		var _spliter=spliter||'/';
	    //然后使用,创建一个日期对象  
	    var dateValue = datevalues.split(_spliter);
	    var custArvDateTwoValue = new Date(dateValue[0], dateValue[1] - 1, dateValue[2]);
	    //调用dateAdd，加两天  
	    custArvDateTwoValue = dateUtil.dateAdd(custArvDateTwoValue, days);
	    var year = custArvDateTwoValue.getFullYear();
	    var month = custArvDateTwoValue.getMonth() + 1;
	    var days = custArvDateTwoValue.getDate();
	    month = month <= 9 ? "0" + month : month;
	    days = days <= 9 ? "0" + days : days;
	    return year + _spliter + month + spliter + days;
	}

};